{% extends 'base/base1.html' %}

{% block main %}
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h3 class="mb-0">添加商品分类</h3>
                </div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        {% for field in form %}
                        <div class="form-group {% if field.name == 'is_active' %}form-check{% endif %} mb-3">
                            {% if field.name != 'is_active' %}
                            <label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
                            {{ field }}
                            {% else %}
                            {{ field }}
                            <label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
                            {% endif %}
                            {% if field.errors %}
                            <div class="text-danger mt-1">
                                {% for error in field.errors %}
                                <small>{{ error }}</small>
                                {% endfor %}
                            </div>
                            {% endif %}
                        </div>
                        {% endfor %}
                        <button type="submit" class="btn btn-primary btn-block">添加分类</button>
                    </form>
                </div>
                <div class="card-footer">
                    <a href="{% url 'main:category' %}" class="btn btn-secondary btn-block">返回分类列表</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}